package com.google.gwt.gfx.client.graphics.vml;

import com.google.gwt.gfx.client.graphics.Circle;
import com.google.gwt.gfx.client.graphics.Ellipse;
import com.google.gwt.gfx.client.graphics.Graphic;
import com.google.gwt.gfx.client.graphics.GraphicFactory;
import com.google.gwt.gfx.client.graphics.Group;
import com.google.gwt.gfx.client.graphics.Line;
import com.google.gwt.gfx.client.graphics.LineString;
import com.google.gwt.gfx.client.graphics.LinearRing;
import com.google.gwt.gfx.client.graphics.Path;
import com.google.gwt.gfx.client.graphics.Rectangle;
import com.google.gwt.gfx.client.style.DefaultStyle;
import com.google.gwt.gfx.client.style.FillStyle;
import com.google.gwt.gfx.client.style.StrokeStyle;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;

public class VMLGraphicFactory implements GraphicFactory {

	@Override
	public Circle createCircle() {
		return new VMLCircle();
	}

	@Override
	public Ellipse createEllipse() {
		return new VMLEllipse();
	}

	@Override
	public FillStyle createFillOf(Graphic g) {
		Element fill = DOM.createElement("v:fill");
		return new VMLFillStyle(g, fill);
	}

	@Override
	public Group createGroup() {
		return new VMLGraphicGroup();
	}

	@Override
	public Line createLine() {
		return new VMLLine();
	}

	@Override
	public Path createPath() {
		return new VMLPath();
	}

	@Override
	public LinearRing createLinearRing() {
		return new VMLLinearRing();
	}

	@Override
	public LineString createLineString() {
		return new VMLLineString();
	}

	@Override
	public DefaultStyle createStyleOf(Graphic g) {
		return new VMLDefaultStyle(g);
	}

	@Override
	public Rectangle createRectangle() {
		return new Rectangle(DOM.createElement("v:rect"));
	}

	@Override
	public StrokeStyle createStrokeOf(Graphic g) {
		Element stroke = DOM.createElement("v:stroke");
		return new VMLStrokeStyle(g, stroke);
	}

	@Override
	public void register(Element element) {
		Element ns = DOM.createElement("xml:namespace");
		DOM.setElementProperty(ns, "ns", "urn:schemas-microsoft-com:vml");
		DOM.setElementProperty(ns, "prefix", "v");
		DOM.appendChild(element, ns);

		Element ax = DOM.createElement("object");
		DOM.setElementProperty(ax, "id", "VMLRender");
		DOM.setElementProperty(ax, "codebase", "vgx.dll");
		DOM.setElementProperty(ax, "classid",
				"CLSID:10072CEC-8CC1-11D1-986E-00A0C955B42E");
		DOM.appendChild(element, ax);
	}

}
